/***********************************************************************
	filename: 	DaterRecover.h
	created:	22/4/2012
	author:		4Ys
	
	purpose:	Implements a virtual class to recover an event by orders 
				from client to server
*************************************************************************/

#include "DaterRecover.h"

namespace Dater
{
	Recover::Recover(std::string recvMessage):_delimiter("\b"),_order(recvMessage)
	{
		split(_order, _delimiter, _splitedData);
		if(_splitedData[0] == "0")
		{
			if(_splitedData[1] == "0")
			{
				_type = "EventAdd";
			}else if(_splitedData[1] == "1")
			{
				_type = "EventDelete";
			}else if(_splitedData[1] == "2")
			{
				_type = "EventUpdate";
			}else if(_splitedData[1] == "3")
			{
				_type = "EventView";
			}
		}else if(_splitedData[0] == "1")
		{
			_type = "Login";
		}else if(_splitedData[0] == "2")
		{
			_type = "SignUp";
		}else if(_splitedData[0] == "3")
		{
			if(_splitedData[1] == "0")
			{
				_type = "GroupCreate";
			}else if(_splitedData[1] == "1")
			{
				_type = "GroupAddMember";
			}else if(_splitedData[1] == "2")
			{
				_type = "GroupAskMember";
			}else if(_splitedData[1] == "3")
			{
				_type = "GroupView";
			}else if(_splitedData[1] == "4")
			{
				_type = "GroupJoin";
			}else if(_splitedData[1] == "5")
			{
				_type = "GroupAskJoin";
			}else if(_splitedData[1] == "6")
			{
				_type = "GroupPublishEvent";
			}else if(_splitedData[1] == "7")
			{
				_type = "GroupResponseToEvent";
			}else if(_splitedData[1] == "8")
			{
				_type = "GroupDeleteMembers";
			}else if(_splitedData[1] == "9")
			{
				_type = "GroupList";
			}else if(_splitedData[1] == "10")
			{
				_type = "AllGroup";
			}else if(_splitedData[1] == "11")
			{
				_type = "GroupSearch";
			}
		}else if(_splitedData[0] == "4")
		{
			if(_splitedData[1] == "0")
			{
				_type = "UserSearch";
			}
		}
	}

	void Recover::split(std::string const& order, std::string delimiter, std::vector<std::string>& splitedVector)
	{
		splitedVector.clear();
		size_t pos = 0, found = 0;
		while(found != std::string::npos)
		{
			found = order.find(delimiter, pos);
			splitedVector.push_back(std::string(order, pos, found - pos));
			pos = found + 1;
		}
	}

	std::string Recover::getErrorMsg()
	{
		return _errorMsg;
	}

	std::string Recover::getType()
	{
		return _type;
	}
}
